package com.shtel.paas.monitorcenter.config.management.alarm.config.web;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmRulesHostEntity;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmRulesHostVO;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmRulesHostidDto;
import com.shtel.paas.monitorcenter.config.management.alarm.config.service.WarningPersonalizedConfigService;
import com.shtel.paas.sdk.core.RefreshableRestController;
import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

@EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.config.management.alarm.config.mapper")
// mybatis存储库类的包路径
@RefreshableRestController
public class WarningPersonalizedConfigController {


	@Autowired
	WarningPersonalizedConfigService service;

	
	@GetMapping("/getWarningPersonalizedConfig")
	public PageInfo<AlarmRulesHostVO> getWarningPersonalizedConfig(@RequestParam("monitoringIndex") String monitoringIndex,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize){
		if(monitoringIndex.equals("")) monitoringIndex = null;
		return service.selectAll(monitoringIndex,page,pageSize);
		
	}
	
	@GetMapping("/getWarningPersonalizedMonitoringKpi")
	public List<AlarmRulesHostEntity> getWarningMonitoringKpi(){
		return service.selectMonitorIndex();
	}
	
	@GetMapping("/updateWarningPersonalizedConfig")
	public int updateWarningPersonalizedConfig(@RequestParam("desc") String desc,
			@RequestParam("kpi") String kpi,
			@RequestParam("hostids") String hostids,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh
			){
		AlarmRulesHostidDto param = new AlarmRulesHostidDto();
		param.setDesc(desc);
		param.setKpi(kpi);
		param.setHostids(hostids);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		
				return service.updateConfig(param);
		
	}
	
	@GetMapping("/insertWarningPersonalizedConfig")
	public int insertWarningPersonalizedConfig(@RequestParam("desc") String desc,
			@RequestParam("kpi") String kpi,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh,
			@RequestParam("hostids") String hostids
			){
		AlarmRulesHostidDto param = new AlarmRulesHostidDto();
		param.setDesc(desc);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		param.setKpi(kpi);
		param.setHostids(hostids);
		return service.insertConfig(param);
		
	}
	
	/*
	 * 更新选择ip操作
	 * 
	 * */
	@GetMapping("/updateWarningPersonalizedSelectIps")
	public int updateWarningPersonalizedSelectIps(@RequestParam("desc") String desc,
			@RequestParam("kpi") String kpi,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh,
			@RequestParam("deletedHostids") String deletedHostids,
			@RequestParam("hostids") String hostids
			){
		AlarmRulesHostidDto param = new AlarmRulesHostidDto();
		param.setDesc(desc);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		param.setKpi(kpi);
		param.setHostids(hostids);
		param.setDeletedHostids(deletedHostids);
		return service.updateWarningPersonalizedSelectIps(param);
		
	}
	
	/*删除操作*/
	@GetMapping("/deleteWarningPersonalizedConfig")
	public int deleteWarningPersonalizedConfig(@RequestParam("desc") String desc){
		return service.deleteConfig(desc);
		
	}
}

